home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / util / misc / VMM_src.lha / VMM / shared_defs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-16  |  13.7 KB  |  448 lines

  1. /* $Id: shared_defs.h,v 3.8 95/12/16 18:37:08 Martin_Apel Exp $ */
  2.  
  3. /* IOPacket can either be a DosPacket (if PageDev == PD_FILE) or a 
  4.  * ExtIOReq structure (if PageDev == PD_PART or PD_PSEUDOPART). 
  5.  * It would have better been a union, but H2I doesn't support unions
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <exec/tasks.h>
  10. #include <exec/alerts.h>
  11. #include <libraries/commodities.h>
  12.  
  13. #define TMP_STACKSIZE 700
  14.  
  15. struct TrapStruct
  16.   {
  17.   struct MinNode                         TS_Node;
  18.   struct Task                           *FaultTask;
  19.   /* If FaultAddress == NULL, this is used for removing a frame. */
  20.   ULONG                                  FaultAddress;
  21.   union
  22.     {
  23.     UWORD                               *u_TopOfStackFrame;
  24.     ULONG                                u_RemFrameSize;
  25.     } u_struct;
  26.   UBYTE                                  TmpStack[TMP_STACKSIZE];
  27.   struct StackSwapStruct                 TmpStackSwap;
  28.   void                                  *IOPacket;
  29.   void                                  *SeekPacket;   /* Only used for 
  30.                                                         * paging to file
  31.                                                         */
  32.   struct FrameDescr                     *FD;
  33.   /* contains the address of the page descriptor If this is NULL,
  34.    * the table for this page is missing
  35.    */
  36.   ULONG                                 *PageDescrAddr;     
  37.   /* contains the address of the table descriptor. 
  38.    */
  39.   ULONG                                 *TableDescrAddr;
  40.   ULONG                                  PhysAddr;
  41.   UWORD                                  WakeupSignal;
  42.   UWORD                                  FramesRemoved;
  43.   ULONG                                  RemFrameFlags;
  44.   };
  45.  
  46. #define RemFrameSize u_struct.u_RemFrameSize
  47. #define TopOfStackFrame u_struct.u_TopOfStackFrame
  48.  
  49. /* Following are the only constants which should be changed for another
  50.  * configuration:
  51.  */
  52.  
  53. #ifdef PAGE4K
  54. #define PAGESIZE        4096
  55. #else
  56. #ifdef PAGE8K
  57. #define PAGESIZE        8192
  58. #else
  59. #define PAGESIZE        4096            /* default */
  60. #endif
  61. #endif
  62.  
  63.  
  64.  
  65. #ifndef NUM_PTR_TABLES
  66. #define NUM_PTR_TABLES       16          /* This gives 512 MB maximum */
  67. #endif
  68.  
  69. #ifndef MAX_FAULTS
  70. #define MAX_FAULTS          20
  71. #endif
  72.  
  73. /*************************** Up to here ************************/
  74.  
  75. #define POINTERS_PER_TABLE 128
  76.  
  77. #if PAGESIZE==4096
  78. #define PAGESIZESHIFT       12
  79. #define PAGES_PER_TABLE     64
  80. #else
  81. #define PAGESIZESHIFT       13
  82. #define PAGES_PER_TABLE     32
  83. #endif
  84.  
  85. #define MAX_TABLES         (POINTERS_PER_TABLE*NUM_PTR_TABLES)
  86. #define MAX_TABLE_PAGES    (PAGES_PER_TABLE*MAX_TABLES/PAGESIZE)
  87.  
  88. /* These are the codes set by VMM when building (parts of) an MMU table */
  89. #define TABLE_RESIDENT     2
  90. #define PAGE_RESIDENT      1
  91. #define INVALID            0
  92.  
  93. #define WRITEPROTECT       0x04
  94. #define USED               0x08
  95. #define MODIFIED           0x10
  96.  
  97. /* Bits for page descriptor */
  98. #define CM_MASK               0x60
  99.  
  100. #define ROOTINDEX(addr)    ((addr) >> 25)
  101. #define POINTERINDEX(addr) (((addr) >> 18) & 0x7f)
  102. #define PAGEINDEX(addr)    (((addr) >> PAGESIZESHIFT) & (PAGES_PER_TABLE-1))
  103. #define PAGEADDR(descr)    ((descr) & ~(PAGESIZE-1))
  104. #define PAGEOFFS(descr)    ((descr) &  (PAGESIZE-1))
  105.  
  106. /* This structure is also used for the 68060. */
  107. struct MMUState40
  108.   {
  109.   ULONG URP,
  110.         SRP,
  111.         ITT0,
  112.         ITT1,
  113.         DTT0,
  114.         DTT1;
  115.   ULONG TC;
  116.   };
  117.  
  118. /* This structure is also used for the 68851. The TT registers are
  119.  * not used in this case.
  120.  */
  121. struct MMUState30
  122.   {
  123.   ULONG TC,
  124.         CRP_Hi,
  125.         CRP_Lo,
  126.         SRP_Hi,
  127.         SRP_Lo,
  128.         TT0,
  129.         TT1;
  130.   };
  131.  
  132. /* Structures for tasks allocating memory */
  133.  
  134. struct HashEntry
  135.   {
  136.   ULONG                                 *Name;
  137.   struct HashEntry                      *NextEntry;
  138.   ULONG                                  MinPublic;
  139.   ULONG                                  MinNonPublic;
  140.   UBYTE                                  Referenced;
  141.   UBYTE                                  HashIndex;
  142.   UWORD                                  NumLongsM1;
  143.   };
  144.  
  145. #define HASHBITS 6
  146. #define HASHTABSIZE (1L << HASHBITS)
  147. #define HASH_VAL(x) (((x)&0x1f8)>>3)
  148.  
  149. struct ExtPort
  150.   {
  151.   struct MsgPort  CxPort;
  152.   struct Task    *PrefsTask;
  153.   LONG            ShowSignal;
  154.   };
  155.  
  156. struct CxParams
  157.   {
  158.   struct ExtPort                        *ExtCxPort;
  159.   CxObj                                 *Broker;
  160.   CxObj                                 *GUIFilter,
  161.                                         *EnableFilter,
  162.                                         *DisableFilter;
  163.   char                                  *PrefsPath;
  164.   char                                  *ConfigPath;        /* name of the initial config file */
  165.   BOOL                                   VMEnable;
  166.   BOOL                                   ForceOverwrite;
  167.   };
  168.  
  169. #define APPEAR_ID  0
  170. #define ENABLE_ID  1
  171. #define DISABLE_ID 2                                         
  172.  
  173. struct VMMsg
  174.   {
  175.   struct Message                         VMMessage;
  176.   struct Task                           *VMSender;
  177.   UWORD                                  VMCommand;
  178.   /* If the reply signal is zero, it means the receiver should free this
  179.    * message.
  180.    */
  181.   UWORD                                  ReplySignal;
  182.   /* The following params are for asking statistics */
  183.   union
  184.     {
  185.     struct
  186.       {
  187.       ULONG                                  st_VMSize;
  188.       ULONG                                  st_VMFree;
  189.       ULONG                                  st_Faults;
  190.       ULONG                                  st_PagesWritten;
  191.       ULONG                                  st_PagesRead;
  192.       ULONG                                  st_Frames;
  193.       ULONG                                  st_PagesUsed;
  194.       ULONG                                  st_PageSize;
  195.       ULONG                                  st_TrapStructsFree;
  196.       } stat_params;
  197.  
  198.     struct 
  199.       {
  200.       struct MemHeader                      *ip_VMHeader;
  201.       struct SignalSemaphore                *ip_VMSema;
  202.              /* A pointer to the memlist name */
  203.       char                                  *ip_MLName;
  204.       } init_params;
  205.  
  206.     struct
  207.       {
  208.       ULONG                                  fp_Address;
  209.       ULONG                                  fp_Size;
  210.       } free_params;
  211.  
  212.     struct
  213.       {
  214.       char                                  *bp_NewWriteBuffer;
  215.       ULONG                                  bp_NewWriteBufferSize;
  216.       } buffer_params;
  217.  
  218.     struct List                             *up_TaskList;
  219.     ULONG                                    lp_PageAddress;
  220.     struct CxParams                         *cp_StartupParams;
  221.     struct VMMConfig                        *vc_CurrentConfig;
  222.     } spec_params;
  223.   };
  224.  
  225. /* Some shortcuts for the above union definitions */
  226.  
  227. #define st_VMSize          spec_params.stat_params.st_VMSize
  228. #define st_VMFree          spec_params.stat_params.st_VMFree
  229. #define st_Faults          spec_params.stat_params.st_Faults
  230. #define st_PagesWritten    spec_params.stat_params.st_PagesWritten
  231. #define st_PagesRead       spec_params.stat_params.st_PagesRead
  232. #define st_Frames          spec_params.stat_params.st_Frames
  233. #define st_PagesUsed       spec_params.stat_params.st_PagesUsed
  234. #define st_PageSize        spec_params.stat_params.st_PageSize
  235. #define st_TrapStructsFree spec_params.stat_params.st_TrapStructsFree
  236.  
  237. #define VMHeader           spec_params.init_params.ip_VMHeader
  238. #define VMSema             spec_params.init_params.ip_VMSema
  239. #define MLName             spec_params.init_params.ip_MLName
  240.  
  241. #define FreeAddress        spec_params.free_params.fp_Address
  242. #define FreeSize           spec_params.free_params.fp_Size
  243.  
  244. #define PageAddress        spec_params.lp_PageAddress
  245.  
  246. #define StartupParams      spec_params.cp_StartupParams
  247.  
  248. #define UsageList          spec_params.up_TaskList
  249.  
  250. #define Config             spec_params.vc_CurrentConfig
  251.  
  252. #define NewWriteBuffer     spec_params.buffer_params.bp_NewWriteBuffer
  253. #define NewWriteBufferSize spec_params.buffer_params.bp_NewWriteBufferSize
  254.  
  255. #define VMCMD_FirstCommand              1468
  256. #define VMCMD_AskAllocMem               (VMCMD_FirstCommand+0)
  257. #define VMCMD_QuitAll                   (VMCMD_FirstCommand+1)
  258. #define VMCMD_InitReady                 (VMCMD_FirstCommand+2)
  259. #define VMCMD_InitFailed                (VMCMD_FirstCommand+3)
  260. #define VMCMD_AskStat                   (VMCMD_FirstCommand+4)   
  261. #define VMCMD_ReqMemHeader              (VMCMD_FirstCommand+5)
  262. #define VMCMD_FreePages                 (VMCMD_FirstCommand+6)
  263. #define VMCMD_LockPage                  (VMCMD_FirstCommand+7)
  264. #define VMCMD_UnlockAllPages            (VMCMD_FirstCommand+8)
  265. #define VMCMD_NewConfig                 (VMCMD_FirstCommand+9)
  266. #define VMCMD_Startup                   (VMCMD_FirstCommand+10)
  267.  
  268. /* Used by the preferences program to work around a bug in the
  269.  * RAM filesystem. When opening a file it allocates memory in VM
  270.  * it doesn't free, when the file is closed.
  271.  */
  272. #define VMCMD_EnableVM                  (VMCMD_FirstCommand+11)
  273. #define VMCMD_DisableVM                 (VMCMD_FirstCommand+12)
  274.  
  275. #define VMCMD_AskVMUsage                (VMCMD_FirstCommand+13)
  276. #define VMCMD_AskConfig                 (VMCMD_FirstCommand+14)
  277. #define VMCMD_NewWriteBuffer            (VMCMD_FirstCommand+15)
  278.  
  279. #define VMCMD_LastCommand               (VMCMD_FirstCommand+15)
  280.  
  281. /*******************************************************************
  282.  * The following alert will occur, if there are no more TrapStructs*
  283.  * during either a page-fault or a context-switch.                 *
  284.  *******************************************************************/
  285.  
  286. #define NoTrapStructsAlertNum (AT_DeadEnd|AO_Unknown|AN_Unknown)
  287.  
  288. /* Error levels */
  289. #define ERR_NOERROR  0        /* Simple message */
  290. #define ERR_CONTINUE 1        /* VM can be continued */
  291. #define ERR_FATAL    2        /* Have to reboot */
  292.  
  293.  
  294. /* The following structure is used for VM, which is freed during a 
  295.  * forbidden section. It's parameters are put into the structure, the struct
  296.  * is chained in a list and the prepager is signalled to really free outside
  297.  * the forbidden section.
  298.  * In order not to allocate such a small structure each time a FreeMem is
  299.  * called in the forbidden state, they are put into a recycling chain
  300.  * after use.
  301.  */
  302.  
  303. struct ForbiddenFreeStruct
  304.   {
  305.   struct ForbiddenFreeStruct            *NextFree;
  306.   void                                  *address;
  307.   ULONG                                  size;
  308.   };
  309.  
  310. /*** Memory tracking ***/
  311. #define TRACK_MAGIC     (('V'<<24)|('M'<<16)|('T'<<8)|'R')
  312.  
  313. /* For use with the MinPublic and MinNonPublic variables */
  314. #define USE_ALWAYS  0L
  315. #define USE_NEVER   0xffffffff
  316.  
  317. /* Defines for code paging */
  318. #define CSWAP TRUE
  319. #define CNOSWAP FALSE
  320.  
  321. /* Defines for data paging */
  322. #define DP_FALSE    0
  323. #define DP_TRUE     1
  324. #define DP_ADVANCED 2
  325.  
  326. #define PD_FILE 0
  327. #define PD_PART 1
  328. #define PD_PSEUDOPART 2
  329.  
  330. #define DYN_MIN 0
  331. #define DYN_MAX 0x40000000
  332.  
  333. #define CFG_MAGIC 0x342ac93a
  334.  
  335. struct VMMConfig
  336.   {
  337.   ULONG CfgMagic;
  338.   UWORD Version,
  339.         Revision;
  340.   ULONG MinMem,
  341.         MaxMem,
  342.         WriteBuffer;
  343.   LONG  VMPriority;
  344.   ULONG MemFlags,
  345.         FileSize,        
  346.         MinVMAlloc,
  347.         ZLeftEdge,
  348.         ZTopEdge,
  349.         UnZLeftEdge,
  350.         UnZTopEdge;
  351.   LONG  DefaultMinPublic,
  352.         DefaultMinNonPublic;
  353.   ULONG NumTaskEntries;
  354.   UWORD PageDev;
  355.   char  EnableHotkey [80],
  356.         DisableHotkey [80],
  357.         PartOrFileName [80];       /* If it's a partition name it includes
  358.                                     * a trailing colon */
  359.   BOOL  StatEnabled,
  360.         StatZoomed,
  361.         MemTracking,
  362.         PatchWB,
  363.         CacheZ2RAM,
  364.         DefaultCodePaging;
  365.   UWORD DefaultDataPaging;
  366.   BOOL  FastROM;
  367.   UWORD Reserved [9];
  368.   };
  369.  
  370. struct OldTaskEntryInFile
  371.   {
  372.   struct MinNode te_Node;
  373.   char  TaskName [40];
  374.   ULONG MinPublic,
  375.         MinNonPublic;
  376.   UWORD DataPaging;
  377.   BOOL  CodePaging;
  378.   BOOL  IsDefault;
  379.   };
  380.   
  381. struct TaskEntryInFile
  382.   {
  383.   ULONG MinPublic,
  384.         MinNonPublic;
  385.   UWORD DataPaging;
  386.   BOOL  CodePaging;
  387.   BOOL  IsDefault;
  388.   UWORD NameLen;         /* Including trailing zero */
  389.   };
  390.  
  391. struct LoadingTaskStruct
  392.   {
  393.   struct MinNode lt_Node;
  394.   struct Task *LoadingTask;
  395.   char        *LoadfileName;
  396.   };
  397.  
  398. #ifdef DEBUG
  399.  
  400. /* Debugging information is held in the following structure. */
  401. #define DEBUG_SIZE  (512L * 1024L)
  402. #define DEBUG_MAGIC1 ((ULONG)(('V' << 16) | ('M' << 8) | 'M'))
  403. #define DEBUG_MAGIC2 ((ULONG)(('D' << 16) | ('B' << 8) | 'G'))
  404.  
  405. struct DebugBuffer
  406.   {
  407.   ULONG Dummy [2];       /* The first two longwords of an AllocAbs cannot be
  408.                           * trusted anyway */
  409.   ULONG Magic1;
  410.   struct DebugBuffer *ThisBuffer;
  411.   char *NextFree;
  412.   char DbgInfo [DEBUG_SIZE - 4 * sizeof (ULONG) 
  413.                            - sizeof (struct DebugBuffer*)
  414.                            - sizeof (char*) ];
  415.   ULONG Magic2;
  416.   };
  417.  
  418. #endif
  419.  
  420.  
  421. #define PAGEHANDLER_NAME    "VMM_PageHandler"
  422. #define PREPAGER_NAME       "VMM_PrePager"
  423. #define VM_MANAGER_NAME     "VMM_Manager"
  424. #define STAT_NAME           "VMM_Statistics"
  425. #define ERR_NAME            "VMM_ErrorHandler"
  426. #define WBUF_ALLOC_NAME     "VMM_WriteBufAllocator"
  427. #define GARBAGE_COLL_NAME   "VMM_EmptyPageCollector"
  428. #define VMPORTNAME          "VMM_Port"
  429. #define CXPORTNAME          "VMM CX Port"
  430. #define STARTER_PORT_STD    "VMM_Starter_Std"
  431. #define STARTER_PORT_LIB    "VMM_Starter_Lib"
  432. #define PROGNAME            "VMM"
  433. #define PROGPATH            "L:VMM-Handler"
  434. #define LIBNAME             "vmm.library"
  435. #define MEMLISTNAME         "VMM Mem (paged)"
  436. #define CFG_FILEBASE        "VMM.prefs"
  437. #define CFG_FILENAME        "ENV:" CFG_FILEBASE
  438. #define MMUCFG_FILENAME     "ENV:VMM_MMU.config"
  439. #define DEFAULT_ENABLE_KEY  "ralt rshift y"
  440. #define DEFAULT_DISABLE_KEY "ralt rshift n"
  441. #define DEFAULT_MINVMSIZE   200L
  442. #define AUTHOR              "Martin Apel"
  443. #define COPYRIGHT           "Copyright 1993-95 Martin Apel"
  444. #define DESCRIPTION         "Virtual memory manager"
  445. #define VER_STRING          "VMM V3.3"
  446.  
  447. #define EMERGENCY_SIGNAL    SIGB_SINGLE
  448.